<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>let变量 case</title>
</head>
<body>
    <div class="container">
        <h2 class="page-header">点击切换颜色</h2>
        <div class="item">123</div>
        <div class="item">345</div>
        <div class="item">567</div>
    </div>
</body>
<script>
    let items = document.getElementsByClassName('item')
    for(var i = 0;i < items.length;i++){
        items[i].onclick = function() {
            this.style.background = 'pink'
        }
    }
</script>
</html>